package com.zlt.appparking.controller;
import com.zlt.appparking.dto.PersonLocationDTO;
import com.zlt.appparking.service.ParkingLotService;
import com.zlt.appparking.vo.ParkingLotVO;
import com.zlt.appparking.vo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("map")
@Slf4j
public class MapController {
    @Autowired
    private ParkingLotService parkingLotService;
    /**
     * 返回最近一定范围内的停车场
     * @param personLocationDTO
     * @return
     */
    @PostMapping("getParks")
    public Result getParks(PersonLocationDTO personLocationDTO){
        System.out.println(personLocationDTO.toString());
        log.debug("经纬度为{}",personLocationDTO.toString());
        try {
            List<ParkingLotVO> parkingLots= parkingLotService.getParks(personLocationDTO);
            return Result.ok("查询成功",parkingLots);
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }
}
